package com.example.park_management.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.park_management.config.Result_zzc;
import com.example.park_management.entity.Processflow_zzc;
import com.example.park_management.service.ProcessflowService_zzc;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/procellflow")
public class ProcessflowController_zzc {

    @Resource
    ProcessflowService_zzc processflowService_zzc;


    @GetMapping("/list")
    private List<Processflow_zzc> list() {
        return processflowService_zzc.list();
    }
    //新增
    @PostMapping("/save")
    public Result_zzc save(@RequestBody Processflow_zzc processflow_zzc) {
        return processflowService_zzc.save(processflow_zzc)? Result_zzc.suc(): Result_zzc.fail();
    }

    @GetMapping("/findByType")
    public Result_zzc findByType(@RequestParam String processname){
        List list = processflowService_zzc.lambdaQuery().eq(Processflow_zzc::getProcessname,processname).list();
        return list.size()>0? Result_zzc.suc(list): Result_zzc.fail();
    }

    //更新
    @PostMapping("/update")
    public Result_zzc update(@RequestBody Processflow_zzc processflow_zzc) {
        return processflowService_zzc.updateById(processflow_zzc)? Result_zzc.suc(): Result_zzc.fail();
    }

    //删除1
    @GetMapping ("/del")
    public Result_zzc del(@RequestParam String processid) {
        return processflowService_zzc.removeById(processid)? Result_zzc.suc(): Result_zzc.fail();
    }

    //修改
    @PostMapping("/mod")
    public boolean mod(@RequestBody Processflow_zzc processflow_zzc) {
        return processflowService_zzc.updateById(processflow_zzc);

    }
    //新增或修改
    @PostMapping("/saveormod")
    public boolean saveormod(@RequestBody Processflow_zzc processflow_zzc) {
        return processflowService_zzc.saveOrUpdate(processflow_zzc);
    }

    //查询（模糊查询,匹配）
    @PostMapping ("/listP")
    public Result_zzc listP(@RequestBody Processflow_zzc processflow_zzc) {
        LambdaQueryWrapper<Processflow_zzc> lambdaQueryWrapper = new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(processflow_zzc.getProcessname())){
            lambdaQueryWrapper.eq(Processflow_zzc::getProcessname, processflow_zzc.getProcessname());
        }
        return Result_zzc.suc(processflowService_zzc.list(lambdaQueryWrapper));
    }
}
